import java.util.*;

public class Test {

    /**
     * 给你一个字符串 jewels 代表石头中宝石的类型，另有一个字符串 stones 代表你拥有的石头。
     * stones 中每个字符代表了一种你拥有的石头的类型，你想知道你拥有的石头中有多少是宝石
     * @param jewels
     * @param stones
     * @return
     */
    public int numJewelsInStones(String jewels, String stones) {
        int cnt = 0;
        Set<Character> set = new HashSet<>();
        for(int i = 0; i < jewels.length(); i++){
            set.add(jewels.charAt(i));
        }
        for(int i = 0; i < stones.length(); i++){
            if(set.contains(stones.charAt(i))){
                cnt++;
            }
        }
        return cnt;
    }

    //除了某个元素只出现一次以外，其余每个元素均出现两次。找出那个只出现了一次的元素
    public int singleNumber(int[] nums) {
        Set<Integer> set = new HashSet<>();
        for(int i = 0 ; i < nums.length; i++){
            if(set.contains(nums[i])){
                set.remove(nums[i]);
            }else{
                set.add(nums[i]);
            }
        }
        for(int i = 0 ; i < nums.length; i++){
            if(set.contains(nums[i])){
                return nums[i];
            }
        }
        return -1;
    }

    public static void main4(String[] args) {

        HashBucket bucket = new HashBucket();
        bucket.put(1,1);
        bucket.put(2,2);
        bucket.put(3,3);
        bucket.put(13,13);
        bucket.put(5,5);
        bucket.put(8,8);
        bucket.put(65,65);
        bucket.put(7,7);

         System.out.println("===");
    }

    public static void main3(String[] args) {

        Set<String> set  = new TreeSet<>();
        set.add("a");
        set.add("c");
        set.add("b");

        set.toArray();

        System.out.println(set);

        for(String s : set) {
            System.out.println(s);
        }
    }

    public static void main2(String[] args) {

        Map<String, Integer> map = new TreeMap<>();
        TreeMap<String, Integer> map2 = new TreeMap<>();

        map2.put("this", 5);
        map2.put("is", 2);
        map2.put("a", 3);

        int val = map2.get("a");
        System.out.println(val);

        //有就输出对应的value，没有就输出defaultValue
        int val2= map.getOrDefault("abc",1);
        System.out.println(val2);



        System.out.println(map2.containsKey("a"));
        System.out.println(map2.containsValue(3));

        Set<Map.Entry<String, Integer>> entries = map2.entrySet();
        for (Map.Entry<String, Integer> entry : entries) {
            System.out.println("Key: "+entry.getKey() + " Value: " + entry.getValue());
        }

        Set<String> set2 = map2.keySet();

        System.out.println("===");

        Collection<Integer> collection = map2.values();

        System.out.println("===");
    }

    public static void main1(String[] args) {
        BinarySearchTree binarySearchTree = new BinarySearchTree();
        binarySearchTree.insert(3);
        binarySearchTree.insert(1);
        binarySearchTree.insert(5);
        binarySearchTree.insert(2);

        System.out.println("===");
        binarySearchTree.remove(1);

        System.out.println("===");

    }

}